package com.my.study.dev;

import cn.hutool.core.util.NumberUtil;
import org.junit.Test;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * https://www.jianshu.com/p/b3699d73142e
 *
 * @author: yidujun
 * @create: 2022/06/14 14:08
 */
public class TestDecimalFormat {

    @Test
    public void test01() {
        double r = 32.4333;
        DecimalFormat decimalFormat = new DecimalFormat("#.00#####");
        String format = decimalFormat.format(r);
        System.out.println(format);

        BigDecimal v1 = new BigDecimal("0.000095");
        BigDecimal v2 = new BigDecimal("0.01");

        System.out.println(NumberUtil.round(v1, 4).toString());

    }

    @Test
    public void test02() {
        String format = String.format("%." + 2 + "f", new BigDecimal("3.4"));
        System.out.println(format);
    }

    @Test
    public void test03() {
        BigDecimal wan = new BigDecimal("10000");
        BigDecimal yi = new BigDecimal("100000000");

        String v = "12033";
        BigDecimal div = NumberUtil.div(new BigDecimal(v), wan, 2);
        System.out.println(div.toString() + "万");
    }

    @Test
    public void test04() {
        double r = 2223344542.4363;
        DecimalFormat decimalFormat = new DecimalFormat(",###.00");
        System.out.println(decimalFormat.format(r));

        double t = 0;
        System.out.println(new DecimalFormat("0.00%").format(t));
    }
}
